package com.sskj.b70.v.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.design.widget.BottomSheetDialog;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.InputFilter;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.bulong.rudeness.RudenessScreenHelper;
import com.jakewharton.rxbinding2.InitialValueObservable;
import com.jakewharton.rxbinding2.widget.RxTextView;
import com.jakewharton.rxbinding2.widget.TextViewAfterTextChangeEvent;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.b70.MyAppLication;
import com.sskj.b70.R;
import com.sskj.b70.adapter.slimadapter.IViewInjector;
import com.sskj.b70.adapter.slimadapter.SlimAdapter;
import com.sskj.b70.adapter.slimadapter.SlimInjector;
import com.sskj.b70.common.App;
import com.sskj.b70.common.Constants;
import com.sskj.b70.common.MoneyValueFilter;
import com.sskj.b70.common.adapter.BaseAdapter;
import com.sskj.b70.common.adapter.ViewHolder;
import com.sskj.b70.common.decoration.DividerLineItemDecoration;
import com.sskj.b70.common.rxbus2.RxBus;
import com.sskj.b70.common.rxbus2.Subscribe;
import com.sskj.b70.common.rxbus2.ThreadMode;
import com.sskj.b70.m.bean.FabiListBean;
import com.sskj.b70.m.bean.PayWayBean;
import com.sskj.b70.mvchelper.ModelRx2DataSource;
import com.sskj.b70.p.fragment.FabiBuyPresenter;
import com.sskj.b70.utils.BottomUpUtil;
import com.sskj.b70.utils.ClickUtil;
import com.sskj.b70.utils.MathUtil;
import com.sskj.b70.utils.NumberUtil;
import com.sskj.b70.utils.ToastUtil;
import com.sskj.b70.v.activity.FabiSellDetailActivity;
import com.sskj.b70.v.activity.LoginActivity;
import com.sskj.b70.v.activity.MainActivity;
import com.sskj.b70.v.activity.SecurityCenterActivity;
import com.sskj.b70.v.base.BaseFragment;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import butterknife.BindView;
import io.reactivex.Observable;

public class FabiBuyAndSellFragment extends BaseFragment<MainActivity, FabiBuyPresenter> {

    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.iv_money_arrow)
    ImageView ivMoneyArrow;
    @BindView(R.id.iv_pay_type_arrow)
    ImageView ivPayTypeArrow;
    @BindView(R.id.tv_pay_type)
    TextView tvPayType;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    private RecyclerView mPayWayRecyclerview;
    private BaseAdapter<PayWayBean> mBaseAdapter;
    private int mPayWx = 0;
    private int mPayAli = 0;
    private int mPayBank = 0;
    private SlimAdapter<FabiListBean> slimAdapter;
    private int curPos;
    private BottomSheetDialog sellDialog;
    private BottomSheetDialog codeDialog;
    private TextView tvSaleName;
    private TextView tvPerPrice;
    private TextView tvPriceTab;
    private View viewPrice;
    private View viewNum;
    private TextView tvNumTab;
    private EditText etPrice;
    private TextView tvTypeAllPrice;
    private TextView tvTypeAllNum;
    private TextView tvLimitPrice;
    private boolean isPrice = true;
    private boolean isBuy;   // false 出售  true 购买Fragment
    private View llPrice;
    private View llNum;
    private EditText etNum;
    private TextView tvSellNum;
    private TextView tvSellPrice;
    private FabiListBean dataItem;
    private String num = "0.0000";
    private String price = "0.00";
    private MVCCoolHelper<List<FabiListBean>> mvcCoolHelper;
    private View mFailView;
    private View mStartLading;
    private View mLoadingProgress;
    private View mFooterView;
    private StringBuffer payType = new StringBuffer();

    public static FabiBuyAndSellFragment newInstance(boolean isBuy) {

        Bundle args = new Bundle();
        args.putBoolean(Constants.IS_BUY, isBuy);  // false 出售  true 购买Fragment
        FabiBuyAndSellFragment fragment = new FabiBuyAndSellFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_fabi_buy;
    }

    @Override
    public FabiBuyPresenter getPresenter() {
        return new FabiBuyPresenter();
    }

    @Override
    public void initView() {
        RxBus.getDefault().register(this);
        isBuy = getArguments().getBoolean(Constants.IS_BUY);  // true 购买Fragment   false  出售Fragment
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(getActivity())
                .setLastDraw(false)
                .setFirstDraw(false)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(getActivity(), 10))
                .setDividerColor(Color.parseColor("#f5f5f5")));
        slimAdapter = SlimAdapter.create().register(R.layout.recy_item_fabi, new SlimInjector<FabiListBean>() {
            @Override
            public void onInject(FabiListBean data, IViewInjector injector) {
                String payType = data.getPayType();// 卖家支付方式(1-微信;2-支付宝;3-银行卡)
                String[] result1 = payType.split(",");
                for (int i = 0; i < result1.length; i++) {
                    if (result1[i].equals("1")) {
                        data.setPay_wx("1");
                    } else if (result1[i].equals("2")) {
                        data.setPay_alipay("1");
                    } else if (result1[i].equals("3")) {
                        data.setPay_backcard("1");
                    }
                }
                injector.clicked(R.id.bt_sale, v -> {
                    if (!MyAppLication.isLogin()) {
                        ToastUtil.showShort(App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment10));
                        LoginActivity.start(getActivity());
                        return;
                    }
                    if (!mActivity.checkIdent()) {
                        return;
                    }
                    if (!mActivity.checkPwdStatus()) {
                        return;
                    }
                    curPos = slimAdapter.getData().indexOf(data);
                    if (isBuy) {
                        if (MyAppLication.getID().equals(slimAdapter.getDataItem(curPos).getStockUserId())) {   // id比较
                            ToastUtil.showShort(App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment11));
                            return;
                        }
                        mPresenter.requsetPayWayList();
                        showSell();

                    } else {
                        if (MyAppLication.getID().equals(slimAdapter.getDataItem(curPos).getStockUserId())) {   // id比较
                            ToastUtil.showShort(App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment12));
                            return;
                        }
                        showSell();
                    }

                }).text(R.id.tv_name, TextUtils.isEmpty(data.getRealname()) ? "***" : data.getRealname().charAt(0) + "**")   // 名字
                        .text(R.id.tv_money, NumberUtil.keepNoZoreMax4(String.valueOf(data.getDealsNum() - data.getTransNum())))  // 成交数量
                        .text(R.id.tv_percent, NumberUtil.keepNoZoreMax2((data.getDealsNum() - data.getTransNum()) / data.getDealsNum() * 100 + "") + "%")  // 比例
                        .text(R.id.tv_num, App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment17) + NumberUtil.keepNoZoreMax4(String.valueOf(data.getTransNum())) + "  USDT")  // 剩余数量
                        .text(R.id.tv_limit_money, data.getLimitNum())  // 限额
                        .text(R.id.tv_china_money, data.getPrice())  // 单价
                        .text(R.id.tv_photo, getFirstName(data.getRealname()))
                        .text(R.id.bt_sale, isBuy ? App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment19) : App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment20))
                        .visibility(R.id.iv_wechat, "1".equals(data.getPay_wx()) && !isBuy ? View.VISIBLE : View.GONE)
                        .visibility(R.id.iv_bank, "1".equals(data.getPay_backcard()) && !isBuy ? View.VISIBLE : View.GONE)
                        .visibility(R.id.iv_alipay, "1".equals(data.getPay_alipay()) && !isBuy ? View.VISIBLE : View.GONE);
            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        ModelRx2DataSource<FabiListBean> dataSource =
                new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<FabiListBean>)
                        page -> mPresenter.getFabiList(page, Constants.PAGE_SIZE, isBuy), Constants.PAGE_SIZE);
        mvcCoolHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcCoolHelper.setDataSource(dataSource);
        mvcCoolHelper.setAdapter(slimAdapter);
        mvcCoolHelper.refresh();
    }


    private String getFirstName(String realname) {
        if (TextUtils.isEmpty(realname)) {
            return "";
        } else {
            return realname.charAt(0) + "";
        }
    }

    /**
     * 显示支付方式
     */
    private void showPayType() {
        View popupView = LayoutInflater.from(getActivity()).inflate(R.layout.popup_fabi_pay_type, null);
        PopupWindow popupWindow = new PopupWindow(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setContentView(popupView);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popupWindow.setOutsideTouchable(true);
//        popupWindow.setAnimationStyle(R.style.AnimDown);
        popupWindow.setClippingEnabled(true);

        popupWindow.showAsDropDown(tvMoney);
    }

    /**
     * 显示销售底部弹窗
     */
    private void showSell() {
        mPayAli = 0;
        mPayWx = 0;
        mPayBank = 0;
        dataItem = slimAdapter.getDataItem(curPos);
        sellDialog = new BottomSheetDialog(getActivity(), R.style.BottomSheetDialog);
        View dialogView = LayoutInflater.from(getActivity())
                .inflate(R.layout.bottom_sheet_fabi_sell, null);
        if (isBuy) {
            mPayWayRecyclerview = dialogView.findViewById(R.id.sell_pay_way);
            // 初始化
            showBuy();
        }
        Button btDeal = dialogView.findViewById(R.id.bt_deal);  // 下单按钮
        tvSaleName = dialogView.findViewById(R.id.tv_sale_name); // 左标题  -- 出售ETH
        tvPerPrice = dialogView.findViewById(R.id.tv_per_price);
        tvPriceTab = dialogView.findViewById(R.id.tv_price_tab);  // C2C计价
        tvNumTab = dialogView.findViewById(R.id.tv_num_tab);  // 出售/购买数量
        viewPrice = dialogView.findViewById(R.id.view_price);  // C2C计价下的下划线
        viewNum = dialogView.findViewById(R.id.view_num);   // 出售数量下的下划线
        etPrice = dialogView.findViewById(R.id.et_price);  // 输入框
        etNum = dialogView.findViewById(R.id.et_num);  // 输入框
        tvTypeAllPrice = dialogView.findViewById(R.id.tv_type_all_price);  // C2C计价  全部出售
        tvTypeAllNum = dialogView.findViewById(R.id.tv_type_all_num);  // 购买数量  全部出售按钮
        tvLimitPrice = dialogView.findViewById(R.id.tv_limit_price);  // 限额
        llPrice = dialogView.findViewById(R.id.ll_price);  // C2C计价  LinearLayout
        llNum = dialogView.findViewById(R.id.ll_num);  // 购买数量 LinearLayout
        tvSellNum = dialogView.findViewById(R.id.tv_sell_num);   // 实际出售/购买
        tvSellPrice = dialogView.findViewById(R.id.tv_sell_price);  // 交易金额
        ClickUtil.click(btDeal, () -> {
            if (Double.valueOf(num) == 0 || Double.valueOf(price) == 0) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment26));
                return;
            }
            if (Double.valueOf(price) < Double.valueOf(dataItem.getMinPrice())) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment27) + dataItem.getMinPrice());
                return;
            }
            if (Double.valueOf(price) > Double.valueOf(dataItem.getMaxPrice())) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment28) + dataItem.getMaxPrice());
                return;
            }
            if (Double.valueOf(num) > Double.valueOf(dataItem.getTransNum())) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment29));
                return;
            } else if (isBuy && mPayWx + mPayAli + mPayBank == 0) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment30));
                return;
            }
            showCode();
        });
        sellDialog.setContentView(dialogView);

        ClickUtil.click(tvNumTab, () -> {
            isPrice = false;
            changeTab();
        });
        ClickUtil.click(tvPriceTab, () -> {
            isPrice = true;
            changeTab();
        });
        etNum.setFilters(new InputFilter[]{new MoneyValueFilter().setDigits(4)});
        etPrice.setFilters(new InputFilter[]{new MoneyValueFilter().setDigits(4)});
        InitialValueObservable<TextViewAfterTextChangeEvent> numFlow = RxTextView.afterTextChangeEvents(etNum);
        InitialValueObservable<TextViewAfterTextChangeEvent> priceFlow = RxTextView.afterTextChangeEvents(etPrice);
        Observable.merge(numFlow, priceFlow)
                .subscribe(textViewAfterTextChangeEvent -> changeResult());
        isPrice = true;
        tvSaleName.setText(isBuy ? App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment31) : App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment32));
        tvPerPrice.setText(dataItem.getPrice());
        changeTab();
        tvNumTab.setText(isBuy ? App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment33) : App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment34));
        etPrice.setHint(isBuy ? App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment35) : App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment36));
        etNum.setHint(isBuy ? App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment37) : App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment38));
        tvTypeAllPrice.setText(isBuy ? App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment39) : App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment40));
        tvTypeAllNum.setText(isBuy ? App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment39) : App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment40));
        ClickUtil.click(tvTypeAllPrice, () -> {
            if (dataItem.getMaxPrice() / dataItem.getOriginPrice() > dataItem.getTransNum()) {
                etPrice.setText(String.format("%s", dataItem.getTransNum() * dataItem.getOriginPrice()));
            } else {
                etPrice.setText(String.format("%s", dataItem.getMaxPrice()));
            }
        });
        ClickUtil.click(tvTypeAllNum, () -> {
//            etNum.setText(MathUtil.divide(dataItem.getMaxPrice(), dataItem.getOriginPrice(), 4, BigDecimal.ROUND_FLOOR) + "");
            etNum.setText(NumberUtil.keepNoZoreMax4(String.valueOf(dataItem.getTransNum())));
        });
        tvLimitPrice.setText(dataItem.getLimitNum());
        sellDialog.show();

    }

    /**
     * 根据C2C计价和出售数量计算总的数量与价格
     */
    private void changeResult() {
        num = etNum.getText().toString();
        price = etPrice.getText().toString();

        if (isPrice) {
            if (TextUtils.isEmpty(price)) {
                num = "0.0000";
                price = "0.00";
            } else {
                num = "" + MathUtil.divide(price, dataItem.getOriginPrice() + "", 4);
            }
        } else {
            if (TextUtils.isEmpty(num)) {
                num = "0.0000";
                price = "0.00";
            } else {
                price = "" + new BigDecimal(num).multiply(new BigDecimal(dataItem.getOriginPrice() + "")).doubleValue();
            }
        }
        tvSellNum.setText(String.format("%s%s USDT", isBuy ? App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment55) : App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment56), num));
        tvSellPrice.setText(String.format("￥%s", MathUtil.round(price, 2)));
    }

    /**
     * 用户选择C2C代价  购买数量样式调整
     */
    private void changeTab() {
        tvPriceTab.setTextColor(getResources().getColor(isPrice ? R.color.bull_black : R.color.fabi_bottom_sheet_gray_color));
        viewPrice.setVisibility(isPrice ? View.VISIBLE : View.GONE);
        tvNumTab.setTextColor(getResources().getColor((!isPrice) ? R.color.bull_black : R.color.fabi_bottom_sheet_gray_color));
        viewNum.setVisibility(!isPrice ? View.VISIBLE : View.GONE);
        if (isPrice) {
            llPrice.setVisibility(View.VISIBLE);
            llNum.setVisibility(View.GONE);
        } else {
            llPrice.setVisibility(View.GONE);
            llNum.setVisibility(View.VISIBLE);
        }
        changeResult();
    }

    private void showPricePop() {
        View popupView = LayoutInflater.from(getActivity()).inflate(R.layout.popup_fabi_price, null);
        PopupWindow popupWindow = new PopupWindow(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setContentView(popupView);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x66000000));
        popupWindow.setOutsideTouchable(true);
//        popupWindow.setAnimationStyle(R.style.AnimDown);
        popupWindow.setClippingEnabled(true);

        popupWindow.showAsDropDown(tvMoney);
    }

    /**
     * 显示验证码底部弹窗
     */
    private void showCode() {
        codeDialog = BottomUpUtil.getPay(getActivity(), mPresenter, (pwd) -> {
            if (isBuy) {  //求购Fragment
//                private int mPayWx = 1;  :1-微信;2-支付宝;3-银行卡
//                private int mPayAli;
//                private int mPayBank;
                if (1 == mPayWx) {
                    payType.append("1");
                }
                if (1 == mPayAli) {
                    if (payType.length() > 0) {
                        payType.append(",2");
                    } else {
                        payType.append("2");
                    }
                }

                if (1 == mPayBank) {
                    if (payType.length() > 0) {
                        payType.append(",3");
                    } else {
                        payType.append("3");
                    }
                }
                mPresenter.order(pwd, dataItem.getOrder_no(), NumberUtil.keepNoZero(num), NumberUtil.keepNoZero(price), isBuy, MyAppLication.getID(), payType.toString());

            } else {
                // 交易密码   委托单号  数量  价钱  出售/求购  id  支付方式
                mPresenter.order(pwd, dataItem.getOrder_no(), NumberUtil.keepNoZero(num), NumberUtil.keepNoZero(price), isBuy, MyAppLication.getID(), "");
            }

        });
        codeDialog.show();
    }

    public void checkOk(String orderNum, boolean isBuy) {
        codeDialog.dismiss();
        sellDialog.dismiss();
        mvcCoolHelper.refresh();
        FabiSellDetailActivity.start(getActivity(), orderNum, isBuy);
    }

    public void checkOk() {
        codeDialog.dismiss();
        sellDialog.dismiss();
        mvcCoolHelper.refresh();
        // 发布成功，页面跳转
        //FabiDetailActivity.start(getActivity());
//        FabiSellDetailActivity.start(getActivity());
    }

    /**
     * 刷新数据
     */
    @Subscribe(code = Constants.FABI_DATING_REFRESH, threadMode = ThreadMode.MAIN)
    public void refresh() {
        if (mvcCoolHelper != null) {
            mvcCoolHelper.refresh();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        RxBus.getDefault().unregister(this);
    }

    /**
     * 购买Fragment弹出框添加支付方式
     */
    public void showBuy() {
        mFailView = LayoutInflater.from(mActivity).inflate(R.layout.layout_reset_loading, null);
        mFooterView = LayoutInflater.from(mActivity).inflate(R.layout.item_text, null);   //添加支付方式
        mFooterView.setOnClickListener(v -> startActivityForResult(new Intent(mActivity, SecurityCenterActivity.class), 1010));
        mPayWayRecyclerview.addItemDecoration(new DividerItemDecoration(mActivity, LinearLayoutManager.VERTICAL));
        mPayWayRecyclerview.setLayoutManager(new LinearLayoutManager(mActivity) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        mBaseAdapter = new BaseAdapter<PayWayBean>(R.layout.buy_item_pay_way, null, mPayWayRecyclerview) {

            @Override
            public void bind(ViewHolder holder, PayWayBean item) {
//                holder.setText(R.id.item_checkbox, item.getTip());
                if ("1".equals(item.getType())) {
                    ((CheckBox) holder.getView(R.id.item_checkbox)).setText(App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment65));
                    ((CheckBox) holder.getView(R.id.item_checkbox)).setCompoundDrawablesWithIntrinsicBounds(R.mipmap.icon_wx, 0, R.drawable.selector_checkbox, 0);
                } else if ("2".equals(item.getType())) {
                    ((CheckBox) holder.getView(R.id.item_checkbox)).setText(App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment67));

                    ((CheckBox) holder.getView(R.id.item_checkbox)).setCompoundDrawablesWithIntrinsicBounds(R.mipmap.icon_ali, 0, R.drawable.selector_checkbox, 0);
                } else if ("3".equals(item.getType())) {
                    ((CheckBox) holder.getView(R.id.item_checkbox)).setText(App.INSTANCE.getString(R.string.strFabiBuyAndSellFragment69));

                    ((CheckBox) holder.getView(R.id.item_checkbox)).setCompoundDrawablesWithIntrinsicBounds(R.mipmap.icon_bank, 0, R.drawable.selector_checkbox, 0);
                }
                holder.setOnCheckedChangeListener(R.id.item_checkbox, (buttonView, isChecked) -> {
                    if (isChecked) {
                        if ("1".equals(item.getType())) {
                            mPayWx = 1;
                            Log.i("info", "1");
                        } else if ("2".equals(item.getType())) {
                            mPayAli = 1;
                            Log.i("info", "2");
                        } else if ("3".equals(item.getType())) {
                            mPayBank = 1;
                            Log.i("info", "3");
                        }
                    } else {
                        if ("1".equals(item.getType())) {
                            mPayWx = 0;
                            Log.i("info", "4");
                        } else if ("2".equals(item.getType())) {
                            mPayAli = 0;
                            Log.i("info", "5");
                        } else if ("3".equals(item.getType())) {
                            mPayBank = 0;
                            Log.i("info", "6");
                        }
                    }
                });
            }
        };
    }

    public void onPayWaySuccess(List<PayWayBean> list) {
        mBaseAdapter.removeHeaderView(mFailView);
        //使用java.util.Iterator
        for (Iterator it = list.iterator(); it.hasNext(); ) {
            PayWayBean obj = (PayWayBean) it.next();
            if (obj.isDisable()) {
                it.remove();
            }
        }
        if (list.size() < 3) {
            if (mBaseAdapter.getFooterLayoutCount() == 0) {
                mBaseAdapter.addFooterView(mFooterView);
            }
        }
        mBaseAdapter.setNewData(list);
    }

    public void onHttpFail() {
        mBaseAdapter.removeFooterView(mFooterView);
        mBaseAdapter.setHeaderView(mFailView);
        mStartLading.setVisibility(View.VISIBLE);
        mLoadingProgress.setVisibility(View.INVISIBLE);
    }

    /**
     * 用户添加支付方式，页面重新返回时，数据进行重新请求
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1010) {
            mPresenter.requsetPayWayList();
        }
    }
}
